package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 攻略文章
 */
@Setter
@Getter
public class StrategyDetail extends BaseDomain {
    public static final int STATE_COMMON = 0;//草稿
    public static final int STATE_RELEASE = 1;//发布
    //public static final int STATE_DISABLE= -1;//禁用

    //标题
    private String title;
    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    //发布时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;
    //序号
    private Integer sequence;
    //所属目录
    private StrategyCatalog catalog;
    //封面
    private String coverUrl;
    //状态
    private Boolean state = false;
    //攻略文章内容
    private StrategyContent strategyContent;

    public String getStateName() {
        return state ? "发布" : "草稿";
    }

    //是否被收藏，用于回显用,默认是没有收藏
    public Boolean collect = false;

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        //将需要的数据添加到map集合中
        map.put("id", id);
        map.put("title", title);
        map.put("sequence", sequence);
        map.put("state", state);
        map.put("coverUrl", coverUrl);
        if (catalog != null) {
            map.put("catalogId", catalog.getId());
            map.put("catalogName", catalog.getName());
            if (catalog.getStrategy() != null) {
                map.put("strategyId", catalog.getStrategy().getId());
            }
        }
        //将map集合转换成json格式的字符串,再返回
        return JSON.toJSONString(map);
    }


}